package com.lk.socket.controller;

import com.lk.base.service.IndexService;
import com.lk.socket.config.MyWebsocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class SocketController {

	@Autowired
	private IndexService indexService;

	@Autowired
	private MyWebsocket myWebsocket;
	@GetMapping("/websocket/main")
	public String sendMsgPage() {
		return "index";
	}

	@PostMapping("/websocket/sendMsg")
	@ResponseBody
	public String sendMsg(String userName,String message) {
		System.out.println("开始给["+userName+"]发送消息：[" + message + "]");
		myWebsocket.sendInfo(userName, message);
		return "ok";
	}




}
